<?php
namespace Admin\Model;
use Think\Model;
header("Content-Type:text/html; charset=utf-8");
class ActicleModel extends Model {
	protected $autoCheckFields = false;  //关闭字段信息的自动检测
	public function index(){	
		$a=check_session();
	
	}
	//文章列表
	public function acticle_list(){

		//接收参数
		$uid=I('uid');
		$acticle=M('acticle');
		$count      = $acticle->where('uid='.$uid)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$list = $acticle->where('uid='.$uid)->limit($Page->firstRow.','.$Page->listRows)->order('ctime desc')->select();
		if ($list===false) {
			return "false";					//select  false查询出错；查询结果为空，则返回NULL，否则返回二维数组
		}
		$arr=array('page'=>$show,'uid'=>$uid,'list'=>$list);
		return $arr;
	}
	//获取uid
	public function add(){
		//接收参数
		$uid=I('uid');
		return $uid;
	}
	//添加文章
	public function add_acticle(){
		//接收参数
		$uid=I('uid');
		$title=I('title');
		$content=I('content');
		$time=date('Y-m-d H:i:s',time());
		$data=array(
				'uid'=>$uid,
				'title'=>$title,
				'content'=>html_entity_decode($content),
				//'img'=>$img,
				'ctime'=>$time,
				'utime'=>$time,
			);
		//print_r($data);exit;
		$res=M('acticle')->data($data)->add();
		$arr=array('uid'=>$uid,'res'=>$res,);
		return $arr;
	}

	public function update(){
		//接收参数
	
		$id=I('id');//print_r($uid);exit('@@@');
		$acticle=M('acticle');
		$list=$acticle->where('id='.$id)->find();
		
		return $list;
	}
	//修改文章
	public function update_acticle(){
		$id=I('id');
		$uid=I('uid');
		$title=I('title');
		$content=I('content');
		//$img=I('img');
		$acticle=M('acticle');
		$data=array(
				'title'=>$title,
				'content'=>html_entity_decode($content),
				'utime'=>date('Y-m-d H:i:s',time()),
				);
		$res_update=$acticle->data($data)->where('id="'.$id.'"')->save();
		$arr=array('uid'=>$uid,'res'=>$res_update,);
		return $arr;
	}
	public function del_acticle(){
		$id=I('id');
		$acticle = M('acticle');
		$res_del=$acticle->where('id='.$id)->delete();
		if ($res_del===false) {
			return '2';
		}else{
			return '1';
		}
	}
}
?>